<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>用户组管理</title>
    <%@ include file="../inc.jsp" %>
  </head>
  
  <body class="easyui-layout">
  <!-- 
    <div data-options="region:'north',border:false" style="height: 0px; overflow: hidden;padding:0px">
    </div>
     -->
    <div data-options="region:'center',border:false"
            style="overflow: hidden;padding:0px" fit="true">
		<table id="dg" class="easyui-datagrid" title="用户组信息列表" fit="true" style="width:700px;height:250px"
				data-options="rownumbers:true,singleSelect:true,url:'${baseUrl}/admin/groups/list',method:'get',toolbar:'#toolbar',
				showFooter:false,pagination:true,idField:'id'">
			<thead>
				<tr>
					<th data-options="field:'group_name',width:100">组名称</th>
					<th data-options="field:'status',width:80,align:'center',formatter:showStatus" >组状态</th>
					<th data-options="field:'desction',width:300,align:'left'">组说明</th>
				</tr>
			</thead>
		</table>
  	</div>
    <!-- 功能菜单 -->
    <div id="toolbar" style="display: none;" align="left">
            <a href="javascript:void(0);" class="easyui-linkbutton"data-options="iconCls:'icon-add',plain:true" onclick="add_fun();" id="add">添加</a>
            <a href="javascript:void(0);" class="easyui-linkbutton"data-options="iconCls:'icon-edit',plain:true" onclick="edit_fun();" id="update">修改</a>
            <a href="javascript:void(0);" class="easyui-linkbutton"data-options="iconCls:'icon-remove',plain:true" onclick="delete_fun();" id="delete">删除</a>
            <a href="javascript:void(0);" class="easyui-linkbutton"data-options="iconCls:'icon-add',plain:true" onclick="update_action();" id="action">权限</a>
            <!-- 
            <a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'brick_delete',plain:true" onclick="$('#searchForm').form('reset');">清空条件</a>
             -->
            <script type="text/javascript">
            function add_fun()
            {
               var params = {
                        winId:'win_add_groups',
                        title:'添加用户组',
                        width:350,
                        height:300,
                        showUrl:'${baseUrl}/admin/groups/au_page',
                        refresh_fun:function(){
                            $('#dg').datagrid('reload');
                        }
                        
                };
                open_fun(params);
            }
            function edit_fun()
            {
                var moduleId=0;
                var row = $('#dg').datagrid('getSelected');
                if(row)
                {
                    moduleId = row.id;
                }
                if(moduleId>0)
                {
                    //winId,title,width,height,showUrl,okUrl,refresh_fun
                    var params = {
                            winId:'win_edit_groups',
                            title:'修改用户组',
                            width:350,
                            height:300,
                            showUrl:'${baseUrl}/admin/groups/au_page?gid='+moduleId,
                            refresh_fun:function(){
                                $('#dg').datagrid('reload');
                            }
                            
                    };
                    open_fun(params);   
                }
                else
                {
                    $.messager.alert("提示","请选择要修改的信息!","info");
                }
            }
            function delete_fun()
            {
                var row = $('#dg').datagrid('getSelected');
                if(!row)
                {
                    $.messager.alert("提示","请选择要删除的用户组！","info");
                }
                else
                {
                    var gid = row.id;
                    $.messager.confirm("删除确认","是否要删除你选择的数据？",function(conf){
                        if(conf)
                        {
                            var url = "${baseUrl}/admin/groups/delete?id="+gid;
                            $.getJSON(url, function(json){
                                if(json.success==0)
                                {
                                    $('#dg').datagrid('reload');
                                }
                                else
                                {
                                    showErrMsg(json);
                                }
                            });
                        }                                       
                    });
                }
                
            }
            
            function update_action()
            {
                var row = $('#dg').datagrid('getSelected');
                if(!row)
                {
                    $.messager.alert("提示","请选择要设置权限的组！","info");
                }
                else
                {
                var gid = row.id;
                var params = {
                        winId:'winPermission',
                        title:'权限设置',
                        width:300,
                        height:500,
                        showUrl:'${baseUrl}/admin/groups/showPremissPage?gid='+gid,
                        okUrl:'${baseUrl}/admin/modules/save',
                        ok_fun:function(){
                            test();
                        },
                        refresh_fun:function(){
                            $('#dg').datagrid('reload');
                        }
                        
                };
                open_fun(params);
                }
            }
            </script>
    </div>
  	
	<div id="wPer" class="easyui-window" title="权限设置" resizable="false" minimizable="false" maximizable="false" collapsible="false" data-options="modal:true,closed:true,iconCls:'icon-save'" style="width:400px;height:400px;padding:0px;">

	</div>
  	
    <script type="text/javascript">
    	//保存权限的信息
		function submitForm()
		{
			$('#formGroup').form('submit',{
				url:'${baseUrl}/admin/groups/save',
				dataType:'json',
				success:function(result){
					var json = $.parseJSON(result);
					if(json.success)
					{
						$('#formGroup').form('clear');
						$('#status').val(9);
						$('#frmAdd').window('close');
						$('#dgGroups').datagrid("reload");
					}
					else
					{
						showErrMsg(json);
					}
				}
			});
		}
    	
    	function showStatus(value,rec,index)
    	{
    		if(value==0)
    			return "<font color='red'>禁用</font>";
    		else
    			return "<font color='green'>启用</font>";
    	}
    	
		var toolbar = [{
			text:'权限设置',
			iconCls:'icon-save',
			handler:function(){
				var row = $('#dg').datagrid('getSelected');
				if(!row)
				{
					alert("请选择要设置权限的组！");
				}
				else
				{
					$('#cenTitle').panel({title:'当前用户组:'+row.group_name});
					$('#gid').val(row.id);
					
					//清除选中的节点
					var nodeSelect = $('#treeModule').tree('getChecked');
					for(var i=0;i<nodeSelect.length;i++){  
                    	var nd = $('#treeModule').tree('find',nodeSelect[i].id);
                    	if(nd!= null)
                    		$('#treeModule').tree('uncheck',nd.target);
                	}  
					
					var url = "${baseUrl}/admin/groupsModules/index?gid="+row.id;  //获取当前用户组所具有的模块信息
					//$('#treeModule')
					$.getJSON(url, function(json){
						$.each(json.mid,function(){
							var node = $('#treeModule').tree('find', this.modules_id);//查找节点  
							if(node != null)
            					$('#treeModule').tree('check', node.target);//将得到的节点选中 
						});
						$('#wPer').window('open');						
					});				
				}
			}
		}];
		
	</script>
  </body>
</html>
